﻿using System;
using System.Windows.Automation;
using System.Windows.Automation.Provider;

namespace AutomationFramework
{
    /// <summary>
    /// A basic implementation of the FragmentRoot provider.  
    /// so it is usually implemented by the fragment that corresponds to the window handle.
    /// </summary>
    [System.Runtime.InteropServices.ComVisible(true)]
    public abstract class FragmentRootProvider : FragmentProvider, IRawElementProviderFragmentRoot
    {
        #region Constructors
        public FragmentRootProvider()
            : base(null, null) // (Parent, FragmentRoot)
        {
            this.fragmentRoot = this;
        }
        #endregion

        #region Overridden Methods
        /// <summary>
        /// The fragment root usually has an HWND, so returning an empty bounding rect.
        /// </summary>
        public override System.Windows.Rect BoundingRectangle
        {
            get { return System.Windows.Rect.Empty; }
        }

        /// <summary>
        /// The fragment root usually has an HWND, so returning an empty runtime ID.
        /// The system will construct one for fragment.
        /// </summary>
        /// <returns></returns>
        public override int[] GetRuntimeId()
        {
            return null;
        }
        #endregion

        #region IRawElementProviderFragmentRoot Members
        /// <summary>
        /// Perform hit testing and return the element that contains this point.
        /// Point is given in screen coordinates.  Return null is the hit is on the fragment
        /// root itself.
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public virtual IRawElementProviderFragment ElementProviderFromPoint(double x, double y)
        {
            return null;
        }

        /// <summary>
        /// Return the fragment with keyboard focus, if there is one.
        /// </summary>
        /// <returns></returns>
        public virtual IRawElementProviderFragment GetFocus()
        {
            return null;
        }

        #endregion
    }
}
